﻿using System;
using System.Text;

namespace GianosNET.Common.Classes
{
    [Serializable]
    public class LogQueue : System.Collections.Generic.Queue<string>
    {
        public int MaxLength { get; set; }

        public LogQueue():this(100){}
        public LogQueue(int maxLength)
        {
            MaxLength = maxLength;
        }

        public new void Enqueue(string s)
        {
            if (this.Count >= MaxLength)
                this.Dequeue();

            base.Enqueue(s);
        }

        public string ToString(string separator)
        {
            StringBuilder sb = new StringBuilder();
            foreach (string s in this)
                sb.AppendFormat("{0}{1}", s, separator ?? "");
            return sb.ToString();
        }
    }
}
